
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>1.1. MobX 要点 · MobX 中文文档</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="concepts.html" />
    
    
    <link rel="prev" href="../" />
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"SangKa","repo":"MobX-Docs-CN","type":"star","size":"small","count":true},{"user":"SangKa","repo":"MobX-Docs-CN","type":"fork","size":"small","count":true}]};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    1. MobX 介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.1.1" data-path="overview.html">
            
                <a href="overview.html">
            
                    
                    1.1. MobX 要点
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.2" data-path="concepts.html">
            
                <a href="concepts.html">
            
                    
                    1.2. 概念与原则
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../refguide/api.html">
            
                <a href="../refguide/api.html">
            
                    
                    2. API概览
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    3. observable 相关
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../refguide/observable.html">
            
                <a href="../refguide/observable.html">
            
                    
                    3.1. observable
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../refguide/observable-decorator.html">
            
                <a href="../refguide/observable-decorator.html">
            
                    
                    3.2. @observable
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../refguide/object.html">
            
                <a href="../refguide/object.html">
            
                    
                    3.3. objects
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../refguide/array.html">
            
                <a href="../refguide/array.html">
            
                    
                    3.4. arrays
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../refguide/map.html">
            
                <a href="../refguide/map.html">
            
                    
                    3.5. maps
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../refguide/boxed.html">
            
                <a href="../refguide/boxed.html">
            
                    
                    3.6. boxed values
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="../refguide/modifiers.html">
            
                <a href="../refguide/modifiers.html">
            
                    
                    3.7 decorators
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    4. 对 observables 作出响应
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../refguide/computed-decorator.html">
            
                <a href="../refguide/computed-decorator.html">
            
                    
                    4.1. (@)computed
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../refguide/autorun.html">
            
                <a href="../refguide/autorun.html">
            
                    
                    4.2. autorun
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../refguide/when.html">
            
                <a href="../refguide/when.html">
            
                    
                    4.3. when
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../refguide/reaction.html">
            
                <a href="../refguide/reaction.html">
            
                    
                    4.4. reaction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../refguide/observer-component.html">
            
                <a href="../refguide/observer-component.html">
            
                    
                    4.5. (@)observer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../best/react.html">
            
                <a href="../best/react.html">
            
                    
                    4.6. 理解 MobX 对何作出响应
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    5. 改变 observables
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../refguide/action.html">
            
                <a href="../refguide/action.html">
            
                    
                    5.1. action
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../best/actions.html">
            
                <a href="../best/actions.html">
            
                    
                    5.2. async actions & flows
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../refguide/object-api.html">
            
                <a href="../refguide/object-api.html">
            
                    
                    5.3. Object api
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" >
            
                <span>
            
                    
                    6. 工具函数
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../refguide/tojson.html">
            
                <a href="../refguide/tojson.html">
            
                    
                    6.1. toJS
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../refguide/extend-observable.html">
            
                <a href="../refguide/extend-observable.html">
            
                    
                    6.2. extendObservable
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../refguide/extending.html">
            
                <a href="../refguide/extending.html">
            
                    
                    6.3. createAtom
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../refguide/observe.html">
            
                <a href="../refguide/observe.html">
            
                    
                    6.4. intercept & observe
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" >
            
                <a target="_blank" href="https://github.com/mobxjs/mobx-utils#frompromise">
            
                    
                    6.5. mobxUtils.fromPromise
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" >
            
                <a target="_blank" href="https://github.com/mobxjs/mobx-utils#fromresource">
            
                    
                    6.6. mobxUtils.fromResource
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" >
            
                <a target="_blank" href="https://github.com/mobxjs/mobx-utils#tostream">
            
                    
                    6.7. mobxUtils.toStream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.8" >
            
                <a target="_blank" href="https://github.com/mobxjs/mobx-utils#fromstream">
            
                    
                    6.8. mobxUtils.fromStream
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.9" >
            
                <a target="_blank" href="https://github.com/mobxjs/mobx-utils#now">
            
                    
                    6.9. mobxUtils.now
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.10" data-path="../refguide/create-transformer.html">
            
                <a href="../refguide/create-transformer.html">
            
                    
                    6.10. mobxUtils.createTransformer
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.11" data-path="../refguide/expr.html">
            
                <a href="../refguide/expr.html">
            
                    
                    6.11. mobxUtils.expr
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.12" data-path="../refguide/api.html">
            
                <a href="../refguide/api.html">
            
                    
                    6.12. complete api overview
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" >
            
                <a target="_blank" href="https://github.com/mobxjs/awesome-mobx#examples">
            
                    
                    7. 博客、 视频及相关项目
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" >
            
                <span>
            
                    
                    8. 贴士与技巧
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../faq/faq.html">
            
                <a href="../faq/faq.html">
            
                    
                    8.1. 常见问题解答
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../best/pitfalls.html">
            
                <a href="../best/pitfalls.html">
            
                    
                    8.2. 常见陷阱与最佳实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../best/decorators.html">
            
                <a href="../best/decorators.html">
            
                    
                    8.3. 如何(不)使用装饰器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../best/trace.html">
            
                <a href="../best/trace.html">
            
                    
                    8.4. 使用 trace 进行调试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../best/store.html">
            
                <a href="../best/store.html">
            
                    
                    8.5. 定义数据存储
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../best/react-performance.html">
            
                <a href="../best/react-performance.html">
            
                    
                    8.6. 优化 React 组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../best/devtools.html">
            
                <a href="../best/devtools.html">
            
                    
                    8.7. 开发工具
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../refguide/spy.html">
            
                <a href="../refguide/spy.html">
            
                    
                    8.8. spy
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../donating.html">
            
                <a href="../donating.html">
            
                    
                    9. 捐赠
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >1.1. MobX 要点</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="mobx-&#x8981;&#x70B9;"><a name="mobx-&#x8981;&#x70B9;" class="plugin-anchor" href="#mobx-&#x8981;&#x70B9;"><i class="fa fa-link" aria-hidden="true"></i></a>MobX &#x8981;&#x70B9;</h1>
<p><a style="color: white; background:green;padding:5px;margin:5px;border-radius:2px" href="https://egghead.io/courses/manage-complex-state-in-react-apps-with-mobx" target="_blank">egghead.io &#x7B2C;1&#x8BFE;: observable &amp; observer</a></p>
<details>
    <summary style="color: white; background:green;padding:5px;margin:5px;border-radius:2px">egghead.io &#x7B2C;1&#x8BFE;: observable &amp; observer</summary>
    <br>
    <div style="padding:5px;">
        <iframe style="border: none;" width="760" height="427" src="https://egghead.io/lessons/javascript-sync-the-ui-with-the-app-state-using-mobx-observable-and-observer-in-react/embed">
    </iframe></div>
    <a style="font-style:italic;padding:5px;margin:5px;" href="https://egghead.io/lessons/javascript-sync-the-ui-with-the-app-state-using-mobx-observable-and-observer-in-react" target="_blank">&#x5728; egghead.io &#x4E0A;&#x89C2;&#x770B;</a>
</details>

<p>&#x5230;&#x76EE;&#x524D;&#x4E3A;&#x6B62;&#xFF0C;&#x8FD9;&#x4E00;&#x5207;&#x90FD;&#x53EF;&#x80FD;&#x542C;&#x8D77;&#x6765;&#x6709;&#x70B9;&#x82B1;&#x54E8;&#xFF0C;&#x4F46;&#x4F7F;&#x7528; MobX &#x5C06;&#x4E00;&#x4E2A;&#x5E94;&#x7528;&#x53D8;&#x6210;&#x54CD;&#x5E94;&#x5F0F;&#x7684;&#x53EF;&#x5F52;&#x7EB3;&#x4E3A;&#x4EE5;&#x4E0B;&#x4E09;&#x4E2A;&#x6B65;&#x9AA4;:</p>
<h2 id="1-&#x5B9A;&#x4E49;&#x72B6;&#x6001;&#x5E76;&#x4F7F;&#x5176;&#x53EF;&#x89C2;&#x5BDF;"><a name="1-&#x5B9A;&#x4E49;&#x72B6;&#x6001;&#x5E76;&#x4F7F;&#x5176;&#x53EF;&#x89C2;&#x5BDF;" class="plugin-anchor" href="#1-&#x5B9A;&#x4E49;&#x72B6;&#x6001;&#x5E76;&#x4F7F;&#x5176;&#x53EF;&#x89C2;&#x5BDF;"><i class="fa fa-link" aria-hidden="true"></i></a>1. &#x5B9A;&#x4E49;&#x72B6;&#x6001;&#x5E76;&#x4F7F;&#x5176;&#x53EF;&#x89C2;&#x5BDF;</h2>
<p>&#x53EF;&#x4EE5;&#x7528;&#x4EFB;&#x4F55;&#x4F60;&#x559C;&#x6B22;&#x7684;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x6765;&#x5B58;&#x50A8;&#x72B6;&#x6001;&#xFF0C;&#x5982;&#x5BF9;&#x8C61;&#x3001;&#x6570;&#x7EC4;&#x3001;&#x7C7B;&#x3002;
&#x5FAA;&#x73AF;&#x6570;&#x636E;&#x7ED3;&#x6784;&#x3001;&#x5F15;&#x7528;&#xFF0C;&#x90FD;&#x6CA1;&#x6709;&#x5173;&#x7CFB;&#x3002;
&#x53EA;&#x8981;&#x786E;&#x4FDD;&#x6240;&#x6709;&#x4F1A;&#x968F;&#x65F6;&#x95F4;&#x6D41;&#x901D;&#x800C;&#x6539;&#x53D8;&#x7684;&#x5C5E;&#x6027;&#x6253;&#x4E0A; <code>mobx</code> &#x7684;&#x6807;&#x8BB0;&#x4F7F;&#x5B83;&#x4EEC;&#x53D8;&#x5F97;&#x53EF;&#x89C2;&#x5BDF;&#x5373;&#x53EF;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> {observable} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;mobx&apos;</span>;

<span class="hljs-keyword">var</span> appState = observable({
    timer: <span class="hljs-number">0</span>
});
</code></pre>
<h2 id="2-&#x521B;&#x5EFA;&#x89C6;&#x56FE;&#x4EE5;&#x54CD;&#x5E94;&#x72B6;&#x6001;&#x7684;&#x53D8;&#x5316;"><a name="2-&#x521B;&#x5EFA;&#x89C6;&#x56FE;&#x4EE5;&#x54CD;&#x5E94;&#x72B6;&#x6001;&#x7684;&#x53D8;&#x5316;" class="plugin-anchor" href="#2-&#x521B;&#x5EFA;&#x89C6;&#x56FE;&#x4EE5;&#x54CD;&#x5E94;&#x72B6;&#x6001;&#x7684;&#x53D8;&#x5316;"><i class="fa fa-link" aria-hidden="true"></i></a>2. &#x521B;&#x5EFA;&#x89C6;&#x56FE;&#x4EE5;&#x54CD;&#x5E94;&#x72B6;&#x6001;&#x7684;&#x53D8;&#x5316;</h2>
<p>&#x6211;&#x4EEC;&#x7684; <code>appState</code> &#x8FD8;&#x6CA1;&#x6709;&#x89C2;&#x5BDF;&#x5230;&#x4EFB;&#x4F55;&#x7684;&#x4E1C;&#x897F;&#x3002;
&#x4F60;&#x53EF;&#x4EE5;&#x521B;&#x5EFA;&#x89C6;&#x56FE;&#xFF0C;&#x5F53; <code>appState</code> &#x4E2D;&#x76F8;&#x5173;&#x6570;&#x636E;&#x53D1;&#x751F;&#x6539;&#x53D8;&#x65F6;&#x89C6;&#x56FE;&#x4F1A;&#x81EA;&#x52A8;&#x66F4;&#x65B0;&#x3002;
MobX &#x4F1A;&#x4EE5;&#x4E00;&#x79CD;&#x6700;&#x5C0F;&#x9650;&#x5EA6;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x66F4;&#x65B0;&#x89C6;&#x56FE;&#x3002;
&#x4E8B;&#x5B9E;&#x4E0A;&#x8FD9;&#x4E00;&#x70B9;&#x53EF;&#x4EE5;&#x8282;&#x7701;&#x4E86;&#x4F60;&#x5927;&#x91CF;&#x7684;&#x6837;&#x677F;&#x6587;&#x4EF6;&#xFF0C;&#x5E76;&#x4E14;&#x5B83;&#x6709;&#x7740;<a href="https://mendix.com/tech-blog/making-react-reactive-pursuit-high-performing-easily-maintainable-react-apps/" target="_blank">&#x4EE4;&#x4EBA;&#x532A;&#x5937;&#x6240;&#x601D;&#x7684;&#x9AD8;&#x6548;</a>&#x3002;</p>
<p>&#x901A;&#x5E38;&#x6765;&#x8BF4;&#xFF0C;&#x4EFB;&#x4F55;&#x51FD;&#x6570;&#x90FD;&#x53EF;&#x4EE5;&#x6210;&#x4E3A;&#x53EF;&#x4EE5;&#x89C2;&#x5BDF;&#x81EA;&#x8EAB;&#x6570;&#x636E;&#x7684;&#x54CD;&#x5E94;&#x5F0F;&#x89C6;&#x56FE;&#xFF0C;MobX &#x53EF;&#x4EE5;&#x5728;&#x4EFB;&#x4F55;&#x7B26;&#x5408;ES5&#x7684;JavaScript&#x73AF;&#x5883;&#x4E2D;&#x5E94;&#x7528;&#x3002;
&#x4F46;&#x662F;&#x5728;&#x8FD9;&#x6240;&#x7528;&#x7684;&#x793A;&#x4F8B;&#x662F; ES6&#x7248;&#x672C;&#x7684; React &#x7EC4;&#x4EF6;&#x89C6;&#x56FE;&#x3002;</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> {observer} <span class="hljs-keyword">from</span> <span class="hljs-string">&apos;mobx-react&apos;</span>;

@observer
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">TimerView</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">React</span>.<span class="hljs-title">Component</span> </span>{
    render() {
        <span class="hljs-keyword">return</span> (
            <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{this.onReset.bind(this)}</span>&gt;</span>
                Seconds passed: {this.props.appState.timer}
            <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span></span>
        );
    }

    onReset() {
        <span class="hljs-keyword">this</span>.props.appState.resetTimer();
    }
};

ReactDOM.render(<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">TimerView</span> <span class="hljs-attr">appState</span>=<span class="hljs-string">{appState}</span> /&gt;</span>, document.body);
</span></code></pre>
<p>(<code>resetTimer</code> &#x51FD;&#x6570;&#x7684;&#x5B9E;&#x73B0;&#x8BF7;&#x89C1;&#x4E0B;&#x8282;)</p>
<h2 id="3-&#x66F4;&#x6539;&#x72B6;&#x6001;"><a name="3-&#x66F4;&#x6539;&#x72B6;&#x6001;" class="plugin-anchor" href="#3-&#x66F4;&#x6539;&#x72B6;&#x6001;"><i class="fa fa-link" aria-hidden="true"></i></a>3. &#x66F4;&#x6539;&#x72B6;&#x6001;</h2>
<p>&#x7B2C;&#x4E09;&#x4EF6;&#x8981;&#x505A;&#x7684;&#x4E8B;&#x5C31;&#x662F;&#x66F4;&#x6539;&#x72B6;&#x6001;&#x3002;
&#x4E5F;&#x5C31;&#x662F;&#x4F60;&#x7684;&#x5E94;&#x7528;&#x7A76;&#x7ADF;&#x8981;&#x505A;&#x4EC0;&#x4E48;&#x3002;
&#x4E0D;&#x50CF;&#x4E00;&#x4E9B;&#x5176;&#x5B83;&#x6846;&#x67B6;&#xFF0C;MobX &#x4E0D;&#x4F1A;&#x547D;&#x4EE4;&#x4F60;&#x5982;&#x4F55;&#x5982;&#x4F55;&#x53BB;&#x505A;&#x3002;
&#x8FD9;&#x662F;&#x6700;&#x4F73;&#x5B9E;&#x8DF5;&#xFF0C;&#x4F46;&#x5173;&#x952E;&#x8981;&#x8BB0;&#x4F4F;&#x4E00;&#x70B9;:
<strong><em>MobX &#x5E2E;&#x52A9;&#x4F60;&#x4EE5;&#x4E00;&#x79CD;&#x7B80;&#x5355;&#x76F4;&#x89C2;&#x7684;&#x65B9;&#x5F0F;&#x6765;&#x5B8C;&#x6210;&#x5DE5;&#x4F5C;</em></strong>&#x3002;</p>
<p>&#x4E0B;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x6BCF;&#x79D2;&#x90FD;&#x4F1A;&#x4FEE;&#x6539;&#x4F60;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x800C;&#x5F53;&#x9700;&#x8981;&#x7684;&#x65F6;&#x5019;UI&#x4F1A;&#x81EA;&#x52A8;&#x66F4;&#x65B0;&#x3002;
&#x65E0;&#x8BBA;&#x662F;&#x5728;<strong>&#x6539;&#x53D8;</strong>&#x72B6;&#x6001;&#x7684;&#x63A7;&#x5236;&#x5668;&#x51FD;&#x6570;&#x4E2D;&#xFF0C;&#x8FD8;&#x662F;&#x5728;&#x5E94;&#x8BE5;<strong>&#x66F4;&#x65B0;</strong>&#x7684;&#x89C6;&#x56FE;&#x4E2D;&#xFF0C;&#x90FD;&#x6CA1;&#x6709;&#x660E;&#x786E;&#x7684;&#x5173;&#x7CFB;&#x5B9A;&#x4E49;&#x3002;
&#x4F7F;&#x7528; <code>observable</code> &#x6765;&#x88C5;&#x9970;&#x4F60;&#x7684;<strong>&#x72B6;&#x6001;</strong>&#x548C;<strong>&#x89C6;&#x56FE;</strong>&#xFF0C;&#x8FD9;&#x8DB3;&#x4EE5;&#x8BA9; MobX&#x68C0;&#x6D4B;&#x6240;&#x6709;&#x5173;&#x7CFB;&#x4E86;&#x3002;</p>
<pre><code class="lang-javascript">appState.resetTimer = action(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">reset</span>(<span class="hljs-params"></span>) </span>{
    appState.timer = <span class="hljs-number">0</span>;
});

setInterval(action(<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">tick</span>(<span class="hljs-params"></span>) </span>{
    appState.timer += <span class="hljs-number">1</span>;
}), <span class="hljs-number">1000</span>);
</code></pre>
<p>&#x53EA;&#x6709;&#x5728;&#x4E25;&#x683C;&#x6A21;&#x5F0F;(&#x9ED8;&#x8BA4;&#x662F;&#x4E0D;&#x542F;&#x7528;)&#x4E0B;&#x4F7F;&#x7528; MobX &#x65F6;&#x624D;&#x9700;&#x8981; <code>action</code> &#x5305;&#x88C5;&#x3002;
&#x5EFA;&#x8BAE;&#x4F7F;&#x7528; action&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x5C06;&#x5E2E;&#x52A9;&#x4F60;&#x66F4;&#x597D;&#x5730;&#x7EC4;&#x7EC7;&#x5E94;&#x7528;&#xFF0C;&#x5E76;&#x8868;&#x8FBE;&#x51FA;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x4FEE;&#x6539;&#x72B6;&#x6001;&#x7684;&#x610F;&#x56FE;&#x3002;
&#x540C;&#x65F6;,&#x5B83;&#x8FD8;&#x81EA;&#x52A8;&#x5E94;&#x7528;&#x4E8B;&#x52A1;&#x4EE5;&#x83B7;&#x5F97;&#x6700;&#x4F73;&#x6027;&#x80FD;&#x3002;</p>
<p>&#x53EF;&#x4EE5;&#x901A;&#x8FC7; <a href="http://jsfiddle.net/mweststrate/wgbe4guu/" target="_blank">JSFiddle</a> &#x6216;&#x8005;&#x514B;&#x9686; <a href="https://github.com/mobxjs/mobx-react-boilerplate" target="_blank">MobX &#x6837;&#x677F;&#x5DE5;&#x7A0B;</a> &#x6765;&#x968F;&#x610F;&#x8BD5;&#x7528;&#x8FD9;&#x4E2A;&#x793A;&#x4F8B;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../" class="navigation navigation-prev " aria-label="Previous page: 1. MobX 介绍">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="concepts.html" class="navigation navigation-next " aria-label="Next page: 1.2. 概念与原则">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"1.1. MobX 要点","level":"1.1.1","depth":2,"next":{"title":"1.2. 概念与原则","level":"1.1.2","depth":2,"path":"intro/concepts.md","ref":"intro/concepts.md","articles":[]},"previous":{"title":"1. MobX 介绍","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[{"title":"1.1. MobX 要点","level":"1.1.1","depth":2,"path":"intro/overview.md","ref":"intro/overview.md","articles":[]},{"title":"1.2. 概念与原则","level":"1.1.2","depth":2,"path":"intro/concepts.md","ref":"intro/concepts.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["github","edit-link","anchors","copy-code-button","github-buttons"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/SangKa/mobx-docs-cn"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"github-buttons":{"buttons":[{"user":"SangKa","repo":"MobX-Docs-CN","type":"star","size":"small","count":true},{"user":"SangKa","repo":"MobX-Docs-CN","type":"fork","size":"small","count":true}]},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"edit-link":{"label":"完善文档","base":"https://github.com/SangKa/mobx-docs-cn/tree/master/docs"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"MobX 中文文档","gitbook":"3.2.2"},"file":{"path":"intro/overview.md","mtime":"2018-09-18T13:06:39.943Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2018-09-18T13:06:52.064Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

